package com.uplooking.controller;

import org.springframework.security.access.AccessDeniedException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
@ControllerAdvice
public class ErrorController {

	@ExceptionHandler(value=Exception.class)
	public String except(Exception e) {
		System.out.println("-------------------------------------------");
		e.printStackTrace();
		System.out.println("-------------------------------------------");
		
		if (e instanceof AccessDeniedException) {
			return "comm/deny";
		}
		
		return "comm/error";
	}
	
	@GetMapping(value="/error/disabled")
	public String disabled() {
		return "comm/disabled";
	}
	
	@GetMapping(value="/error/incorrect")
	public String incorrect() {
		return "comm/incorrect";
	}
	
	@GetMapping(value="/error/notfound")
	public String notfound() {
		return "comm/notfound";
	}
	
	@GetMapping(value="/error/deny")
	public String deny() {
		return "comm/deny";
	}
}
